// DOM Ready
function getActiveActions(){	
	$.getJSON(
		'http://localhost:8080/app-r/json/activeActions.jsp?callback=?',
		{ no: 15 },
		function(data){
			var $nf = $("#actions-feed");
			if(data == null || data.length == 0){
				var $li = $([
								'<li>',
									'<div class="actions-container" style="text-align:center">',
									'没有正在进行的活动，快去发起个活动吧',
									'</div>',
									'<p class="actions-date"></p>',
									'<a class="actions-link" href="http://www.baidu.com" target="_self">发起活动</a>',
								'</li>'
								].join('')).appendTo($nf);
			}else{
				$.each(data, function(){
					var $li = $([
					'<li>',
						'<div class="actions-container">',
						this.nick,'说：',this.regTextEscape,
						'</div>',
						'<p class="actions-date">', this.startTimeStr, '</p>',
						'<a class="actions-link" href="http://t.qq.com/t/', this.regTid, '" target="_blank">查看详情</a>',
					'</li>'
					].join('')).appendTo($nf);
				})
				
			}
			$nf.fuelNews({nav: $("#actions > span")}).find('h3').center();;	
		})
}

function getActionsByPage(pageNum,pageSize){
	if(pageNum === null){
		pageNum = 0;
	}
	if(pageSize === null){
		pageSize = 20;
	}
	count = 0;
	currentPageNo = 1;
	$.getJSON(
			'http://localhost:8080/app-r/json/actions.jsp?callback=?',
			{ no: pageSize,p:pageNum },
			function(data){
				var $nf = $("#action-list-feed");
				$nf.empty();
				if(data == null || data.result.length == 0){
					var $li = $([
									'<li>',
										'<div class="actions-container" style="text-align:center">',
										'没有正在进行的活动，快去发起个活动吧',
										'</div>',
										'<p class="actions-date"></p>',
										'<a class="actions-link" href="http://www.baidu.com" target="_self">发起活动</a>',
									'</li>'
									].join('')).appendTo($nf);
				}else{
					$.each(data.result, function(){
						var $li = $([
						'<li>',
						
						'<div class="msgBox">',
						'<div class="userName">',
						this.nick,'：',
						'</div>','<div class="msgCnt">',
							this.regTextEscape,
						'</div>',
						'</div>',
						'</li>'
						].join('')).appendTo($nf);
					})
					
				}
				count = data.totalCount;
				currentPageNo = data.currentPageNo;
				$("#action-list-feed li").hover(function(){
					$(this).addClass("lihover");
				},function () {
					$(this).removeClass("lihover");
				});
				var num_entries = count
				// 创建分页
				$("#pagination").pagination(num_entries, {
					num_edge_entries: 1, //边缘页数
					num_display_entries: 3, //主体页数
					items_per_page: 3, //每页显示1项
					current_page:currentPageNo - 1,
					callback:pageselectCallback,
					prev_text: "上一页",
					next_text: "下一页"
				});
			})
			
	
}
function pageselectCallback(page_index, jq){
	
	getActionsByPage(page_index + 1,3)
	return false;
}




function getMyActionsByPage(pageNum,pageSize){
	if(pageNum === null){
		pageNum = 0;
	}
	if(pageSize === null){
		pageSize = 20;
	}
	count = 0;
	currentPageNo = 1;
	$.getJSON(
			'http://localhost:8080/app-r/json/actions.jsp?callback=?',
			{ no: pageSize,p:pageNum },
			function(data){
				var $nf = $("#my-action-list-feed");
				$nf.empty();
				if(data == null || data.result.length == 0){
					var $li = $([
									'<li>',
										'<div class="actions-container" style="text-align:center">',
										'没有正在进行的活动，快去发起个活动吧',
										'</div>',
										'<p class="actions-date"></p>',
										'<a class="actions-link" href="http://www.baidu.com" target="_self">发起活动</a>',
									'</li>'
									].join('')).appendTo($nf);
				}else{
					$.each(data.result, function(){
						var $li = $([
'<li>',
'<div class="msgBox">',
'<div class="userName">',
this.nick,'：',
'</div>','<div class="msgCnt">',
	this.regTextEscape,
'</div>',
'</div>',
'</li>'
].join('')).appendTo($nf);
					})
					
				}
				count = data.totalCount;
				currentPageNo = data.currentPageNo;
				$("#my-action-list-feed li").hover(function(){
					$(this).addClass("lihover");
				},function () {
					$(this).removeClass("lihover");
				});
				var num_entries = count
				// 创建分页
				$("#myactions-page").pagination(num_entries, {
					num_edge_entries: 1, //边缘页数
					num_display_entries: 3, //主体页数
					items_per_page: 3, //每页显示1项
					current_page:currentPageNo - 1,
					callback:pageselectCallback4MyActions,
					prev_text: "上一页",
					next_text: "下一页"
				});
			})
			
	
}
function pageselectCallback4MyActions(page_index, jq){
	
	getMyActionsByPage(page_index + 1,3)
	return false;
}



function getMyJoinActionsByPage(pageNum,pageSize){
	if(pageNum === null){
		pageNum = 0;
	}
	if(pageSize === null){
		pageSize = 20;
	}
	count = 0;
	currentPageNo = 1;
	$.getJSON(
			'http://localhost:8080/app-r/json/actions.jsp?callback=?',
			{ no: pageSize,p:pageNum },
			function(data){
				var $nf = $("#my-join-actions-list-feed");
				$nf.empty();
				if(data == null || data.result.length == 0){
					var $li = $([
									'<li>',
										'<div class="actions-container" style="text-align:center">',
										'没有正在进行的活动，快去发起个活动吧',
										'</div>',
										'<p class="actions-date"></p>',
										'<a class="actions-link" href="http://www.baidu.com" target="_self">发起活动</a>',
									'</li>'
									].join('')).appendTo($nf);
				}else{
					$.each(data.result, function(){
						var $li = $([
'<li>',

'<div class="msgBox">',
'<div class="userName">',
this.nick,'：',
'</div>','<div class="msgCnt">',
	this.regTextEscape,
'</div>',
'</div>',
'</li>'
].join('')).appendTo($nf);
					})
					
				}
				count = data.totalCount;
				currentPageNo = data.currentPageNo;
				$("#my-join-actions-list-feed li").hover(function(){
					$(this).addClass("lihover");
				},function () {
					$(this).removeClass("lihover");
				});
				var num_entries = count
				// 创建分页
				$("#myjoinactions-page").pagination(num_entries, {
					num_edge_entries: 1, //边缘页数
					num_display_entries: 3, //主体页数
					items_per_page: 3, //每页显示1项
					current_page:currentPageNo - 1,
					callback:pageselectCallback4MyJoinActions,
					prev_text: "上一页",
					next_text: "下一页"
				});
			})
			
	
}
function pageselectCallback4MyJoinActions(page_index, jq){
	
	getMyJoinActionsByPage(page_index + 1,3)
	return false;
}